package cn.edu.zafu.bigdata.bd121.im.common;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Scanner;

/**
 * 处理客户端发来的消息
 *
 * @author 202211090121
 */
public class HandleMessage implements Runnable {

    /**
     * 接收消息的scanner
     */
    private final Scanner scanner;

    /**
     * 持续接收消息并打印到控制台
     */
    @Override
    public void run() {
        while (true) {
            if (scanner.hasNextLine()) {
                String string = scanner.nextLine();
                System.out.println("收到来自对方的消息：" + string);
            }
        }
    }

    public HandleMessage(Socket socket) throws IOException {
        scanner = new Scanner(new InputStreamReader(socket.getInputStream()));
    }
}
